home *** CD-ROM | disk | FTP | other *** search
/ Libris Britannia 4 / science library(b).zip / science library(b) / PROGRAMM / PROGEDIT / 0748.ZIP / MISC < prev    next >
Text File  |  1986-12-29  |  1KB  |  49 lines

  1. /* These contain some miscellaneous routines. */
  2.  
  3. #define CTRL_C  3
  4. #define CTRL_W  'W'-'A'+1
  5.  
  6. init()
  7. {
  8.   assign_key("copy_ch_above", CTRL_C);
  9.   assign_key("copy_wd_above", CTRL_W);
  10. }
  11.  
  12. copy_ch_above()
  13. {
  14.   int c;
  15.  
  16.   if (up())             /* if we're not at the first line */
  17.   {                     /* go up and get the char above the cursor position */
  18.     c = currchar();
  19.     down();
  20.     if (c == 0)         /* check for a NULL character */
  21.       c = ' ';
  22.     insert(chr(c));     /* insert the string equivalent of the character */
  23.   }
  24. }
  25.  
  26. copy_wd_above()
  27. {
  28.   int col1, col2;
  29.   string str;
  30.  
  31.   save_position();
  32.   str = "";
  33.  
  34.   if (up() && !is_eol())                        /* move the cursor up */
  35.   {
  36.     col1 = currcol();                           /* save the starting column */
  37.     while (!is_eol() && currchar() == ' ')      /* move to 1st char of word */
  38.       right();
  39.     while (!is_eol() && currchar() != ' ')      /* move to end of word */
  40.       right();
  41.     col2 = currcol();                           /* get current column */
  42.     if (col2 > col1)                            /* extract the word */
  43.       str = substr(currline(), col1, col2 - col1);
  44.   }
  45.  
  46.   restore_position();
  47.   insert(str);
  48. }
  49.